package cn.lei.uicontrols;

import android.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class AtyUsingRadioGroup extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aty_using_radio_group);

        RadioGroup radioGroup = (RadioGroup) findViewById(R.id.rgSex);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int rbId = group.getCheckedRadioButtonId();
                RadioButton radioButton = (RadioButton) AtyUsingRadioGroup.this.findViewById(rbId);
                new AlertDialog.Builder(AtyUsingRadioGroup.this).setTitle("性别").setMessage(radioButton.getText()).setPositiveButton("关闭", null).show();
            }
        });
    }
}
